﻿using MediatR;
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ZhaoXi.MSACommerce.UserCases.Common.Behaviors;

namespace ZhaoXi.MSACommerce.UserCases.Common
{
    public static class DependencyInjection
    {
        public static IServiceCollection AddUserCaseCommon(this IServiceCollection services, Assembly assembly)
        {
            services.AddAutoMapper(assembly);
            
            services.AddValidatorsFromAssembly(assembly);

           
            services.AddMediatR(cfg =>
            {
                cfg.RegisterServicesFromAssemblies(assembly);
                cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
            });

            return services;
        }
    }
}
